package com.largeOrange.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;

/**
 * @author 大橙子
 * @version 1.0
 * @since 1.0
 * 元数据处理器,公共字段填充
 */
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("insert字段填充...");
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("createUser", IdThreadLocal.getId());
        metaObject.setValue("updateUser", IdThreadLocal.getId());
    }
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("update字段填充...");
        metaObject.setValue("updateTime", LocalDateTime.now());
        System.out.println("填充字段----------->>"+IdThreadLocal.getId()+"线程----》"+Thread.currentThread().getName());
        metaObject.setValue("updateUser", IdThreadLocal.getId());
    }
}
